﻿const ImageGenerationTask = require('./src/models/ImageGenerationTask');
const { sequelize } = require('./src/config/database');

async function checkTaskId(taskId) {
  try {
    await sequelize.authenticate();
    console.log('数据库连接成功');
    
    console.log(正在检查 task_id: +taskId);
    console.log(	ask_id 类型: +typeof taskId);
    console.log(	ask_id 长度: +taskId.length);
    
    // 查询特定的task_id
    const task = await ImageGenerationTask.findOne({
      where: { task_id: taskId },
      attributes: ['task_id', 'status', 'image_url', 'created_at', 'user_uuid']
    });
    
    if (task) {
      console.log('✅ 找到任务记录:');
      console.log(JSON.stringify(task.toJSON(), null, 2));
    } else {
      console.log('❌ 未找到指定的任务记录');
      
      // 查询最近的10个任务
      console.log('\n📋 最近的10个任务记录:');
      const recentTasks = await ImageGenerationTask.findAll({
        limit: 10,
        order: [['created_at', 'DESC']],
        attributes: ['task_id', 'status', 'image_url', 'created_at']
      });
      
      recentTasks.forEach((t, index) => {
        console.log({index + 1}. {t.task_id} - {t.status} - {t.created_at});
      });
    }
    
  } catch (error) {
    console.error('错误:', error);
  } finally {
    await sequelize.close();
  }
}

// 使用方法：node check_task_id.js 你的task_id
const taskId = process.argv[2];
if (!taskId) {
  console.log('用法: node check_task_id.js <task_id>');
  console.log('例如: node check_task_id.js 12f337ec-c206-480f-8669-f58a3695efa6');
  process.exit(1);
}

checkTaskId(taskId);
